<?php
defined('IN_IXDCW') or exit('Access Denied');
$do_rule = new ErnieRuleModule();
$do_prize = new ErnieModule();
$do_statistics = new ErnieStatistics();
$menus = array (
    array('添加'.$MOD['name'], '?moduleid='.$moduleid.'&action=add'),
    array($MOD['name'].'列表', '?moduleid='.$moduleid),
    array('回收站', '?moduleid='.$moduleid.'&action=recycle'),
);


switch($action) {
	case 'add':
		if($submit) {
			if($do_rule->pass($post)) {


				$do_rule->add($post);


				dmsg('添加成功', '?moduleid='.$moduleid.'&action='.$action);
			} else {
				msg($do_rule->getErrmsg());
			}
		} else {
			foreach($do_rule->getFields() as $v) {
				isset($$v) or $$v = '';
			}
			$content = '';
			$status = 3;
			$addtime = timetodate($DT_TIME);
			$item = array();
			$menuid = 0;
			$tname = $menus[$menuid][0];
			isset($url) or $url = '';
			if($url) {
				$tmp = fetch_url($url);
				if($tmp) extract($tmp);
			}
			$pagebreak = 0;
			include tpl('edit', $module);
		}
	break;
	case 'edit':

		$id or msg();

		$do_rule->setid($id);
		if($submit) {
			if($do_rule->pass($post)) {


				$do_rule->edit($post);


				dmsg('修改成功', $forward);
			} else {
				msg($do_rule->getErrmsg());
			}
		} else {
			$item = $do_rule->getOne();
			extract($item);
			$pagebreak = strpos($item['content'], '[pagebreak]') === false ? 0 : 1;
			$menuon = array('4', '3', '2', '1');
			$menuid = $menuon[$status];
			$tname = '修改'.$MOD['name'];
			include tpl($action, $module);
		}
	break;

	case 'delete':
		$id or msg('请选择'.$MOD['name']);
		isset($recycle) ? $do_rule->recycle($id) : $do_rule->delete($id);
		dmsg('删除成功', $forward);
	break;
	case 'deletelog':
		$id or msg('请选择'.$MOD['name']);
		isset($recycle) ? $do_prize->recycle($id) : $do_prize->delete($id);
		dmsg('删除成功', $forward);
		break;
	case 'restore':
		$id or msg('请选择'.$MOD['name']);
		$do_rule->restore($id);
		dmsg('还原成功', $forward);
	break;
	case 'restorelog':
		$id or msg('请选择'.$MOD['name']);
		$do_prize->restore($id);
		dmsg('还原成功', $forward);
		break;
	case 'clear':
		$do_rule->clear();
		dmsg('清空成功', $forward);
	break;
	case 'clear':
		$do_rule->clear();
		dmsg('清空成功', $forward);
		break;
	case 'clearlog':
		$do_prize->clear();
		dmsg('清空成功', $forward);
		break;
	case 'recycle':
		$lists = $do_rule->getList('status=0'.$condition, $dorder[$order]);
		$menuid = 4;
		include tpl('index', $module);
	break;
	case 'recyclelog':
		$lists = $do_prize->getList('status=0'.$condition, $dorder[$order]);
		$menuid = 4;
		include tpl('index_prize', $module);
		break;
	case 'log':
		$lists = $do_prize->getList('status=3'.$condition);

		$menuid = 1;
		include tpl('index_prize', $module);
	break;
	case 'statistics':
		$lists = $do_statistics->getList(''.$condition);
		$menuid = 1;
		include tpl('index_log', $module);
	break;
	default:
		$lists = $do_rule->getList('status=3'.$condition);

		$menuid = 1;
		include tpl('index', $module);
	break;
}

?>